package com.zjxh.zjxh.common.util;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.google.common.collect.Maps;
import java.util.Collection;
import java.util.Map;

/**
 * @author: Oyp
 * @date: 2021/1/15 on 9:35 上午
 * @desc:
 */
public class PageUtil {

  public static <T, E> Map<String, Object> toPage(IPage<T> iPage, Collection<E> list) {
    Map<String, Object> map = Maps.newHashMapWithExpectedSize(3);
    map.put("total", iPage.getTotal());
    map.put("pages", iPage.getPages());
    map.put("records", list);
    return map;
  }

  public static <T, E> NPage<E> toNPage(IPage<T> iPage, Collection<E> list) {
    NPage<E> page = new NPage<>();
    page.setPages(iPage.getPages())
        .setRecords(list)
        .setTotal(iPage.getTotal())
        .setSize(iPage.getSize())
        .setCurrent(iPage.getCurrent());
    return page;
  }
}
